﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Security;
namespace gamexpert.member
{
    public partial class BillingNShippingAddress : System.Web.UI.Page
    {
        DataSet1 ds;
        DataSet1TableAdapters.my_billshipinfoTableAdapter da;
        MembershipUser u;
        DataSet1.my_billshipinfoRow r;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!User.Identity.IsAuthenticated)
            {
                Response.Redirect("~/Login.aspx");
            }   
            string onclick="onclick";
            string javascript="if(!confirm('The changes are not saved.Are you sure you want to cancel?'))return false;";
            btnCancel.Attributes.Add(onclick,javascript);
            btnCancel2.Attributes.Add(onclick,javascript);
            btnCancel3.Attributes.Add(onclick,javascript);
            btnCancel4.Attributes.Add(onclick,javascript);
            
            
            if (!IsPostBack)
            {
                MultiView1.ActiveViewIndex = 0;
                ds = new DataSet1();
                da = new gamexpert.DataSet1TableAdapters.my_billshipinfoTableAdapter();
                u = Membership.GetUser(User.Identity.Name);
               da.FillByUserId(ds.my_billshipinfo, (Guid)u.ProviderUserKey);
               if (ds.my_billshipinfo.Rows.Count > 0)
               {
                   r = (DataSet1.my_billshipinfoRow)ds.my_billshipinfo.Rows[0];
                   txtsfirstname.Text = r.sfirstname;
                   txtslastname.Text = r.slastname;
                   txtsemail.Text = r.semail;
                   txtsaddress.Text = r.saddress;
                   txtscity.Text = r.scity;
                   txtsstate.Text = r.sstate;
                   txtszip.Text = r.szip;
                   txtsphone.Text = r.sphone;

                   txtbfirstname.Text = r.bfirstname;
                   txtblastname.Text = r.blastname;
                   txtbemail.Text = r.bemail;
                   txtbaddress.Text = r.baddress;
                   txtbcity.Text = r.bcity;
                   txtbstate.Text = r.bstate;
                   txtbzip.Text = r.bzip;
                   txtbphone.Text = r.bphone;
               }
            }
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/member/MemberArea.aspx");
        }

      
        void addData()
        {
            ds = new DataSet1();
            da = new gamexpert.DataSet1TableAdapters.my_billshipinfoTableAdapter();
            u = Membership.GetUser(User.Identity.Name);
            Guid userid = (Guid)u.ProviderUserKey;
            da.FillByUserId(ds.my_billshipinfo, (Guid)u.ProviderUserKey);

            if (ds.my_billshipinfo.Rows.Count <= 0)
            {
                //ds.my_billshipinfo.Addmy_billshipinfoRow(r);
                ds.my_billshipinfo.Addmy_billshipinfoRow(userid, txtsfirstname.Text, txtslastname.Text, txtsemail.Text, txtsaddress.Text, txtscity.Text, txtsstate.Text, cbobcountry.SelectedValue, txtszip.Text, txtsphone.Text, txtbfirstname.Text, txtblastname.Text, txtbemail.Text, txtbaddress.Text, txtbcity.Text, txtbstate.Text, cbobcountry.SelectedValue, txtbzip.Text, txtbphone.Text);
            }
            else
            {
                r = (DataSet1.my_billshipinfoRow)ds.my_billshipinfo.Rows[0];
                r.sfirstname = txtsfirstname.Text;
                r.slastname = txtslastname.Text;
                r.semail = txtsemail.Text;
                r.saddress = txtsaddress.Text;
                r.scity = txtscity.Text;
                r.sstate = txtsstate.Text;
                r.szip = txtszip.Text;
                r.sphone = txtsphone.Text;

                r.bfirstname = txtbfirstname.Text;
                r.blastname = txtblastname.Text;
                r.bemail = txtbemail.Text;
                r.baddress = txtbaddress.Text;
                r.bcity = txtbcity.Text;
                r.bstate = txtbstate.Text;
                r.bzip = txtbzip.Text;
                r.bphone = txtbphone.Text;
            }
            da.Update(ds.my_billshipinfo);
        }

        protected void btnCancel_Click1(object sender, EventArgs e)
        {
            Response.Redirect("~/member/MemberArea.aspx");
        }

        protected void btnNext1_Click(object sender, EventArgs e)
        {
            MultiView1.ActiveViewIndex = 1;
        }

        protected void btnCancel2_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/member/MemberArea.aspx");
        }

        protected void btnCancel3_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/member/MemberArea.aspx");
        }

        protected void btnPrev1_Click(object sender, EventArgs e)
        {
            MultiView1.ActiveViewIndex = 0;
        }

        protected void btnNext2_Click(object sender, EventArgs e)
        {
            if (chkSame.Checked == true)
            {
                MultiView1.ActiveViewIndex = 3;
            }
            else
            {
                MultiView1.ActiveViewIndex = 2;
            }
        }

        protected void btnCancel4_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/member/MemberArea.aspx");
        }

        protected void btnPrev3_Click(object sender, EventArgs e)
        {
            if (chkSame.Checked == true)
            {
                MultiView1.ActiveViewIndex = 1;
            }
            else
            {
                MultiView1.ActiveViewIndex = 2;
            }
        }

        protected void btnPrev2_Click(object sender, EventArgs e)
        {
            MultiView1.ActiveViewIndex = 1;
        }

        protected void btnNext3_Click(object sender, EventArgs e)
        {
            MultiView1.ActiveViewIndex = 3;
        }
        void copyBilltoShip()
        {
            txtsfirstname.Text = txtbfirstname.Text;
            txtslastname.Text = txtblastname.Text;
            txtsemail.Text = txtbemail.Text;
            txtsaddress.Text = txtbaddress.Text;
            txtscity.Text = txtbcity.Text;
            txtsstate.Text = txtbstate.Text;
            cboscountry.SelectedValue = cbobcountry.SelectedValue;
            txtszip.Text = txtbzip.Text;
            txtsphone.Text = txtbphone.Text;
        }
        void DisplayInfo()
        {
            if (chkSame.Checked == true)
            {
                lblbfirstname.Text = txtbfirstname.Text;
                lblblastname.Text = txtblastname.Text;
                lblbemail.Text = txtbemail.Text;
                lblbaddress.Text = txtbaddress.Text;
                lblbcity.Text = txtbcity.Text;
                lblbstate.Text = txtbstate.Text;
                lblbcountry.Text = cbobcountry.SelectedValue;
                lblbzip.Text = txtbzip.Text;
                lblbphone.Text = txtbphone.Text;

                lblsfirstname.Text = txtbfirstname.Text;
                lblslastname.Text = txtblastname.Text;
                lblsemail.Text = txtbemail.Text;
                lblsaddress.Text = txtbaddress.Text;
                lblscity.Text = txtbcity.Text;
                lblsstate.Text = txtbstate.Text;
                lblscountry.Text = cbobcountry.SelectedValue;
                lblszip.Text = txtbzip.Text;
                lblsphone.Text = txtbphone.Text;
            }
            else
            {
                lblbfirstname.Text = txtbfirstname.Text;
                lblblastname.Text = txtblastname.Text;
                lblbemail.Text = txtbemail.Text;
                lblbaddress.Text = txtbaddress.Text;
                lblbcity.Text = txtbcity.Text;
                lblbstate.Text = txtbstate.Text;
                lblbcountry.Text = cbobcountry.SelectedValue;
                lblbzip.Text = txtbzip.Text;
                lblbphone.Text = txtbphone.Text;

                lblsfirstname.Text = txtsfirstname.Text;
                lblslastname.Text = txtslastname.Text;
                lblsemail.Text = txtsemail.Text;
                lblsaddress.Text = txtsaddress.Text;
                lblscity.Text = txtscity.Text;
                lblsstate.Text = txtsstate.Text;
                lblscountry.Text = cboscountry.SelectedValue;
                lblszip.Text = txtszip.Text;
                lblsphone.Text = txtsphone.Text;
            }
        }

        protected void MultiView1_ActiveViewChanged(object sender, EventArgs e)
        {
            if (MultiView1.ActiveViewIndex == 3)
            {
                DisplayInfo();
            }
        }

        protected void btnFinish_Click(object sender, EventArgs e)
        {
            if (chkSame.Checked == true)
            {
                copyBilltoShip();
            }
            addData();
            MultiView1.ActiveViewIndex = 4;
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/member/MemberArea.aspx");
        }
    }
}
